<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SampleDNS</title>
</head>
<style>
    div {
        text-indent: 25px;
        margin-top: 10px;
    }
    .inputText {
        width: 25%;
    }
</style>
<body>
    <div class="container">
        <div>
            <label>域名: </label>
            </label><input type="text" readonly id="DomanName" placeholder="请输入域名" class="inputText">
        </div>
        <div>
            <label>类型: </label>
            </label><input type="text" readonly id="Type" class="inputText">
        </div>

        <div>
            <label>解析: </label>
            </label><input type="text" id="IP" placeholder="解析地址" class="inputText">
        </div>

        <div>
            <label>备注: </label>
            </label><input type="text" id="Remark" placeholder="备注" class="inputText">
        </div>

        <div>
            <button onclick="updateDnsInfo()">修改记录</button>
        </div>
    </div>
</body>
</html>

<script src="js/jquery.js"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script>

    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    var DomanNames = getQueryVariable("DomainName");
    var ServerKeys = getQueryVariable("ServerKeys");
    var findDatas = {
        DomanName: DomanNames,
        ServerKeys: ServerKeys
    }

    $.ajax({
        type: "POST",
        url: "/findOne",
        data: findDatas,
        async: false,
        dataType: "JSON",
        success:function (data) {
            if (data.code == 0) {
                DomanName.value = data.data[0].DomainName;
                Type.value = data.data[0].Type;
                IP.value = data.data[0].Ip;
                Remark.value = data.data[0].Remark;
                ServerKeys = data.data[0].ServerKeys;
            } else {
                alert("查询失败");
                window.location.href="index.html";
            }
        }
    })
    
    function updateDnsInfo() {
        $.ajax({
            type: "POST",
            url: "/update",
            data: {
                "DomanName": DomanName.value,
                "IP": IP.value,
                "Remark": Remark.value,
                "ServerKeys": ServerKeys
            },
            dataType: "JSON",
            success:function (data) {
                if (data.code == 0) {
                    alert("修改成功");
                    window.location.href="index.html";
                } else {
                    alert("修改失败");
                    window.location.href="index.html";
                }
            },error:function (data) {
                alert("修改失败");
                window.location.href="index.html";
            }
        });
    }
</script>